C
C     ..................................................................
C
C	 SUBROUTINE PHI
C
C	 PURPOSE
C	    TO COMPUTE THE PHI COEFFICIENT BETWEEN TWO VARIABLES  WHICH
C	    ARE DICHOTOMOUS.
C
C	 USAGE
C	    CALL PHI (N,U,V,HU,HV,P,CH,XP,IE)
C
C	 DESCRIPTION OF PARAMETERS
C	    N  - NUMBER OF OBSERVATIONS
C	    U  - INPUT VECTOR OF LENGTH N CONTAINING THE FIRST DICHOTO-
C		 MOUS VARIABLE
C	    V  - INPUT VECTOR OF LENGTH N CONTAINING THE SECOND DICHOTO-
C		 MOUS VARIABLE
C	    HU - INPUT NUMERICAL CODE WHICH INDICATES THE HIGHER
C		 CATEGORY OF THE FIRST VARIABLE.  ANY OBSERVATION IN
C		 VECTOR U WHICH HAS A VALUE EQUAL TO OR GREATER THAN HU
C		 WILL BE CLASSIFIED IN THE HIGHER CATEGORY.
C	    HV - INPUT NUMERICAL CODE FOR VECTOR V, SIMILAR TO HU
C	    P  - PHI COEFFICIENT COMPUTED
C	    CH - CHI-SQUARE COMPUTED AS A FUNCTION OF PHI COEFFICIENT
C		 (DEGREES OF FREEDOM FOR CHI-SQUARE = 1)
C	    XP - COMPUTED VALUE OF THE MAXIMAL PHI COEFFICIENT THAT
C		 CAN BE ATTAINED IN THE PROBLEM
C	    IE - IF IE IS NON-ZERO, SOME CELL IN THE 2 BY 2 TABLE IS
C		 NULL.	IF SO, P, CH, AND XP ARE SET TO 10**75.
C
C	 REMARKS
C	    VARIABLES U AND V MUST BE SPECIFIED NUMERIC.
C	    THE PHI COEFFICIENT IS A SPECIAL CASE OF THE
C	    PEARSON PRODUCT-MOMENT CORRELATION WHEN BOTH VARIABLES ARE
C	    BINARY.
C
C	 SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C	    NONE
C
C	 METHOD
C	    REFER TO P. HORST, 'PYSCHOLOGICAL MEASUREMENT AND
C	    PREDICTION', P. 94 (WADSWORTH, 1966).
C
C     ..................................................................
C
      SUBROUTINE PHI (N,U,V,HU,HV,P,CH,XP,IE)
C
      DIMENSION U(1),V(1)
C
C	 CONSTRUCT A 2X2 CONTINGENCY TABLE
C
      IE=0
      A=0.0
      B=0.0
      C=0.0
      D=0.0
C
      DO 40 I=1,N
      IF(U(I)-HU) 10,25,25
   10 IF(V(I)-HV) 15,20,20
   15 D=D+1.0
      GO TO 40
   20 B=B+1.0
      GO TO 40
   25 IF(V(I)-HV) 30,35,35
   30 C=C+1.0
      GO TO 40
   35 A=A+1.0
   40 CONTINUE
      IF(A) 100,100,41
   41 IF(B) 100,100,42
   42 IF(C) 100,100,43
   43 IF(D) 100,100,44
C
C	 COMPUTE THE PHI COEFFICIENT
C
   44 P=(A*D-B*C)/ SQRT((A+B)*(C+D)*(A+C)*(B+D))
C
C	 COMPUTE CHI-SQURE
C
      T=N
      CH=T*P*P
C
C	 COMPUTE THE MAXIMAL PHI COEFFICIENT
C
      P1=(A+C)/T
      P2=(B+D)/T
      P3=(A+B)/T
      P4=(C+D)/T
      IF(P1-P2) 75, 45, 45
   45 IF(P3-P4) 65, 50, 50
   50 IF(P1-P3) 60, 55, 55
   55 XP=SQRT((P3/P4)*(P2/P1))
      GO TO 95
   60 XP=SQRT((P1/P2)*(P4/P3))
      GO TO 95
   65 IF(P1-P4) 70, 55, 55
   70 XP=SQRT((P2/P1)*(P3/P4))
      GO TO 95
   75 IF(P3-P4) 90, 80, 80
   80 IF(P2-P3) 60, 85, 85
   85 XP=SQRT((P4/P3)*(P1/P2))
      GO TO 95
   90 IF(P2-P4) 70, 85, 85
C
   95 RETURN
  100 IE=1
      P=1.E38
      CH=1.E38
      XP=1.E38
      GO TO 95
      END







T((P2/P1)*(P3/P4))
      GO TO 95
   75 IF(P3-P4) 90, 80,